<include file="public/shop_header"/>

<body>

<!--main-->
<style type="text/css">
body{ background:#f4f4f4;}
</style>
<div class="cpMain">
  <ul class="myAddress-list">

    <volist name="list" id="list">
      <li>
        <div class="li-t clearfix">
          <span class="name fl">{$list.username}</span> <span class="tel fr">{$list.phone}</span>
        </div>
        <div class="li-c">
          {$list.region}{$list.address}
        </div>
        <div class="li-f clearfix">
          <div class="arge fl">
            <input type="radio" name="moren" id="moren_{$list.address_id}" onclick="tab_default(this)" <if condition="$list.is_default">checked</if> data-id="{$list.address_id}" >
            <label for="moren_{$list.address_id}">设为默认地址</label>
          </div>
          <div class="delete fr">
            <a href="{:U('User/edit_address',array('item_id' => $list.address_id))}"><i class="iconfont">&#xe60e;</i>编辑</a> <a href="javascript:;" data-id="{$list.address_id}" onclick="del_address(this)" ><i class="iconfont">&#xe618;</i>删除</a>
          </div>
        </div>
      </li>
    </volist>

  </ul>
  <div class="myAddress-button">
    <a href="{:U('User/add_address')}" class="tj-btn" style="margin-bottom: 10px;">添加收获地址</a>
    <a href="{:U('Goods/Index')}" class="tj-btn">返回首页</a>
  </div>
</div>
<!--main End-->

<script>
  //点击切换默认地址
  function tab_default(obj){
      var item_id = $(obj).attr("data-id");
      $.ajax({
          type: 'post',
          url: "/Home/User/tab_default.html",
          data: {item_id:item_id},
          dataType: 'json',
          success: function (data) {
              if (data.status == 200) {
                  layer.msg(data.msg,{icon:1,time:2000});
              }else{
                  layer.msg(data.msg,{icon:2,time:2000},function(){if(data.url){ window.location.href = data.url;}});
              }
          }
      })
  }


  //删除地址
  function del_address(obj){
      var item_id = $(obj).attr("data-id");
      $.ajax({
          type: 'post',
          url: "/Home/User/del_address.html",
          data: {item_id:item_id},
          dataType: 'json',
          success: function (data) {
              if (data.status == 200) {
                  layer.msg(data.msg,{icon:1,time:2000},function(){ window.location.reload();});
              }else{
                  layer.msg(data.msg,{icon:2,time:2000},function(){if(data.url){ window.location.href = data.url;}});
              }
          }
      })
  }

</script>

</body>
</html>
